// 数据校验文件
const joi = require('joi')

/**
 * string() 值必须是字符串
 * alphanum() 值只能是包含 a-zA-Z0-9 的字符串
 * min(length) 最小长度
 * max(length) 最大长度
 * required() 值是必填项，不能为 undefined
 * pattern(正则表达式) 值必须符合正则表达式的规则
 */

const username = joi.string().alphanum().min(3).max(16).required()
const password = joi.string().pattern(/^[\S]{6,12}$/).required()

exports.login_schema = {
  body: {
    username, password
  }
}
exports.reg_schema = {
  body: {
    username, password , repassword:password,email:joi.string().email().required(),code:joi.string().length(6).required()
  }
}


exports.get_info = {
  query: {
    id: joi.number()
  }
}

exports.put_info = {
  body:{
    phone: joi.string().required(),
    avatar: joi.string().required(),
    gender: joi.number().required()
  }
}

exports.resetPwd = {
  body:{
    oldPassword: joi.string().min(6).max(20).required(),
    newPassword1: joi.string().min(6).max(20).required(),
    newPassword2: joi.string().min(6).max(20).required()
  }
}

exports.wechat_login_schema = {
  body:{
    code:joi.string().required()
  }
}